import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/index")
public class Index extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //拿到session会话,不存在session对象，不会自动创建对象
        HttpSession httpSession=req.getSession(false);
        String username=(String)httpSession.getAttribute("username");
        Integer count=(Integer)httpSession.getAttribute("count");
        //访问次数加加
        count=count+1;
        //将访问次数写回到session中
        httpSession.setAttribute("count",count);
        //设置字符格式
        resp.setContentType("text/html;charset=utf8");
        resp.getWriter().write("<h3>欢迎"+username+"第"+count+"次"+"来到<h3>");

    }
}
